﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoccaStore.Data.Entity.Model;
using RoccaStore.Services;

namespace RoccaStore.Data.Entity.Entities
{
    public class AddressBookEntities : EntitiesBase<RoccaStoreEntities>, IAddressBookRepository
    {
        public List<Contact> GetByAccountID(int accountId)
        {
            return Context.Contact.Where(a => a.AccountID == accountId).ToList();
        }

        public Contact GetByID(int id)
        {
            return Context.Contact.FirstOrDefault(a => a.ID == id);
        }

        public int Save(Contact addressBook)
        {
            Context.Contact.Add(addressBook);
            Context.SaveChanges();
            return addressBook.ID;
        }

        public Contact GetByEmail(string email, int accountId)
        {
            return Context.Contact.FirstOrDefault(a => a.Email == email && a.AccountID == accountId);
        }

        public List<Contact> GetBySearchTerm(string searchTerm, int accountId)
        {
            return Context.Contact.Where(c => c.Email.Contains(searchTerm) && c.AccountID == accountId).ToList();
        }
    }
}
